package org.dromara.common.mongo;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ChatAccusationMongoDao {

    @Autowired
    private MongoOperations mongoOperations;
    private static String collectionName = "chat_accusation";

    public List<ChatAccusation> getList(Long userId) {
        Query query = new Query();
        query.addCriteria(Criteria.where("userId").is(userId));
        Sort sort = Sort.by(new Sort.Order(Sort.Direction.DESC, "createTime"));
        query.with(sort);
        return mongoOperations.find(query, ChatAccusation.class, collectionName);
    }

    public void save(ChatAccusation chatAccusation) {
        mongoOperations.insert(chatAccusation, collectionName);
    }
}
